<?php
namespace app\admin\controller;

use app\BaseController;
use app\Request;
use app\admin\model\SystemRole as SystemRoleModel;
use app\admin\validate\{PositiveIntegerValidate, SystemRoleValidate}; 

class SystemRole extends BaseController
{
    public function createOrUpdateRole(Request $request)
    {
        (new SystemRoleValidate())->checkParams();
        $data = $request->post();

        $this->success('success', SystemRoleModel::roleCreateOrUpdate($data), 201);
    }

    public function menuRoleList() 
    {
        $this->success('success', SystemRoleModel::menuRole(), 200); 
    }

    public function getRoleDetail()
    {
        $this->success('success', SystemRoleModel::roleDetail(), 200); 
    }

    public function getRoleList(Request $request)
    {
        $params = $request->get();
        $this->success('success', SystemRoleModel::roleList($params), 200);
    }

    public function delRole(Request $request)
    {
        (new PositiveIntegerValidate)->checkParams();

        $id = $request->param('id');
        $this->success('success', SystemRoleModel::delRole($id), 204);
    }
}